<?php
namespace app\admin\controller;

class Index extends Common
{
    public function index()
    {	
        return $this->fetch();
    }

    //个人中心
    public function personal_center()
    {
    	if(request()->isAjax()){
    		$account = input('account');
    		$passwd = input('passwd');

    		if(!empty($account)){
    			$data['account'] = $account;
    		}

    		if(!empty($passwd)){
    			$data['password'] = md5($passwd);
    		}

    		$file = request()->file('image');

    		// 移动到框架应用根目录/public/uploads/ 目录下
		    if($file){
		        $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
		        if($info){
		            $data['head_image'] = $info->getSaveName(); 
		        }else{
		            // 上传失败获取错误信息
		            echo $file->getError();
		        }
		    }

    		$result = db('admin')->where(['id'=>$this->info['id']])->update($data);
    		if(!$result)return $this->error('修改失败!');
    		$this->success('修改成功');
    	}

    	$info = db('admin')->where(['id'=>$this->info['id']])->find();
    	$this->assign('member',$info);
    	$this->assign('img_path',IMG_PATH);
    	return $this->fetch();
    }
}
